import { useRef } from "react";

const useThrottle = (fn: Function, time = 400) => {
  const startTime = useRef(+new Date());
  return () => {
    const now = +new Date();
    if (now - startTime.current >= time) {
      fn();
      startTime.current = now;
    }
  };
};

export default useThrottle;
